package com.ssm.driver.controller;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Map;

import com.ssm.driver.entity.vo.InentoryVo;
import com.ssm.driver.entity.vo.LiuShuiDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.ssm.driver.entity.SsmLiushuiEntity;
import com.ssm.driver.service.SsmLiushuiService;
import com.ssm.common.utils.PageUtils;
import com.ssm.common.utils.R;

import javax.annotation.Resource;


/**
 * 
 *
 * @author ssm
 * @email sunlightcs@gmail.com
 * @date 2023-03-19 17:31:38
 */
@RestController
@RequestMapping("driver/ssmliushui")
public class SsmLiushuiController {
    @Resource
    StringRedisTemplate stringRedisTemplate;
    @Autowired
    private SsmLiushuiService ssmLiushuiService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = ssmLiushuiService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Integer id){
		SsmLiushuiEntity ssmLiushui = ssmLiushuiService.getById(id);

        return R.ok().put("ssmLiushui", ssmLiushui);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody SsmLiushuiEntity ssmLiushui){
		ssmLiushuiService.save(ssmLiushui);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody SsmLiushuiEntity ssmLiushui){
		ssmLiushuiService.updateById(ssmLiushui);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Integer[] ids){
		ssmLiushuiService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }
    @RequestMapping("/findsy/{token}")
    public R findsy(@PathVariable("token") String token){
        Object sjId1 = stringRedisTemplate.opsForHash().get(token, "sjId");
        if (sjId1 == null) {
            return R.error("请重新登录");
        }
        ArrayList<LiuShuiDto> LiuShuiList = ssmLiushuiService.getBysjId(Integer.parseInt(sjId1.toString()));

        return R.ok().put("liuShuiList",LiuShuiList);
    }
}
